package com.jishuo.nontax.api.socket.handle;

import com.jishuo.base.bean.BaseResult;
import com.jishuo.base.bean.ErrorCodeEnum;
import com.jishuo.base.util.SpringContextUtil;
import com.jishuo.nontax.api.socket.ApiHandle;
import com.jishuo.nontax.bean.vo.PayScaleBillVO;
import com.jishuo.nontax.bfc.service.PayScaleBillService;
import org.dom4j.Element;

/**
 * 交管二八分成接口
 * @auther dinggaofei
 * @Date 2023/2/3 13:53
 */
public class PayScaleBillApi implements ApiHandle {
    @Override
    public BaseResult execute(String head, Element body) {
        if (head.equals("getIllegalactivityScale")) { // 获取交管二八分成单据
            String billNum = body.elementText("billnum");
            if (billNum == null || billNum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");
            PayScaleBillService payScaleBillService = (PayScaleBillService) SpringContextUtil.getBean("payScaleBillService");
           return  payScaleBillService.getIllegalactivityScale(billNum);
        } else if (head.equals("sendIllegalactivityScaleBankaffirm")) {//交管二八分成缴费信息
            String billNum = body.elementText("billnum");
            if (billNum == null || billNum.length() == 0)
                return new BaseResult(ErrorCodeEnum.PARAM_ERR.getCode(), "参数错误[billnum]");
            PayScaleBillService payScaleBillService = (PayScaleBillService) SpringContextUtil.getBean("payScaleBillService");
            int n = payScaleBillService.sendIllegalactivityScaleBankaffirm(billNum);
            if (n == 0) {
                return new BaseResult(ErrorCodeEnum.SYS_ERR);
            }
            BaseResult result = new BaseResult();
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        } else if (head.equals("setIllegalactivityScaleBankaffirm")) {//记录交管二八分成单据付款信息
            String billnum = body.elementText("billnum");
            String billno = body.elementText("billo");
            String bankaffirm = body.elementText("bankaffirm");
            String paybankdt = body.elementText("paybankdt");
            String bankstation = body.elementText("bankstation");
            PayScaleBillVO payScaleBillVO = new PayScaleBillVO();
            payScaleBillVO.setBillnum(billnum);
            payScaleBillVO.setBillno(Integer.parseInt(billno));
            payScaleBillVO.setBankaffirm(bankaffirm);
            payScaleBillVO.setPaybankdt(paybankdt);
            payScaleBillVO.setBankstation(bankstation);
           PayScaleBillService payScaleBillService = (PayScaleBillService) SpringContextUtil.getBean("payScaleBillService");
           BaseResult result = payScaleBillService.setIllegalactivityScaleBankaffirm(payScaleBillVO);
            int n = result.isSuccess() ? 1 : 0;
            result.setData("<returninfo>" + n + "</returninfo>");
            return result;
        }
        return null;
    }
}
